package com.vcms.controller.customer.states;

import com.vcms.controller.customer.TransactionController;
import com.vcms.controller.customer.CoinReceiver;
import com.vcms.controller.customer.states.TransactionState;

public class CoinInputState extends TransactionState {

	public CoinInputState(TransactionController transactionController){
		setTransactionController(transactionController);
	}
	
	@Override
	public boolean handleDisplayCustomerPanel() {
		System.out.println("[CoinInputState] - Incorrect state to handle display customer panel!");
		
		return false;
	}
	
	@Override
	public boolean handleStartTransaction() {
		System.out.println("[CoinInputState] - Incorrect state to handle start transaction!");
		
		return false;
	}
	
	@Override
	public boolean handleProcessMoneyReceived() {
		System.out.println("Inside Coin Input State Handle - Enter Coins");
		
		TransactionController transactionController = getTransactionController();
		int totalInserted = transactionController.getTotalInserted();
		float price = transactionController.getPrice();
		
		if(totalInserted >= price){
			// Change the state to dispense drink if total coins inserted is more than price
			// Transit to DISPENSEDRINK state
			transactionController.transitState(StateFactory.getInstance().create(TransactionState.DISPENSEDRINK, transactionController));
			
			transactionController.completeTransaction();
		}else{
			CoinReceiver coinReceiver = transactionController.getCoinReceiver();
			coinReceiver.continueReceive();
		}		
		
		return true;
	}
	
	@Override
	public boolean handleCompleteTransaction() {
		System.out.println("[CoinInputState] - Incorrect state to complete transaction!");
		
		return false;
	}	
	
	@Override
	public boolean handleTerminateTransaction() {
		System.out.println("[CoinInputState] - Incorrect state to terminate transaction!");
		
		return false;
	}
	
	@Override
	public boolean handleTerminateFault() {
		System.out.println("[CoinInputState] - Incorrect state to handle terminate fault!");
		
		return false;
	}
	
	@Override
	public boolean handleRefreshCustomerPanel() {
		System.out.println("[CoinInputState] - Incorrect state to handle refresh customer panel!");
		
		return false;
	}
	
	public void printState(){
		System.out.println("- Coin Input State -");
	}
}
